﻿@using ZR.CodeGenerator
@using ZR.Model.System.Generate
@using Infrastructure.Extensions;
@* @model ZR.CodeGenerator.Model.GenerateDto; *@
@{
    var genTable = Model.GenTable;
    var genTableOptions = genTable.Options;
    var bizNameFirstLower=genTable.FunctionCode.FirstLowerCase();
    var subTableOptions = Model.SubTableOptions;
    var options = Model.GenOptions;
    var replaceDto = Model.ReplaceDto;
    bool showCustomInput = Model.GenTable.Columns.Any((Func<GenTableColumn, bool>)(f => f.HtmlType.Equals(GenConstants.HTML_CUSTOM_INPUT, StringComparison.OrdinalIgnoreCase)));
}
import request from '@@/utils/request'
@if(replaceDto.SelectMulti == 1)
{
@:import QS from 'qs'
}
@if(replaceDto.ShowBtnExport)
{
@:import { downFile } from '@@/utils/request'
}

/**
 * @(genTable.FunctionName)分页查询
 * @@param {查询条件} data
 */
export function get@(genTable.FunctionCode)PageList(data) {
  return request({
    url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/pageList',
    method: 'post',
    data: data,
@if(replaceDto.SelectMulti == 1)
{
    @:paramsSerializer: function (params) {
        @:return QS.stringify(params, { indices: false })
    @:}
}
  })
}

@if (genTableOptions.IsTreeTable)
{
@:export function get@(genTable.FunctionCode)TreeSelectList(data){
    @:return request({
        @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/treeSelectList',
        @:method: 'post',
        @:data: data,
    @:})
@:}
}


@if(genTable.TplCategory == "tree")
{
@:/**
@:* @(genTable.FunctionName)tree查询
@:* @@param {查询条件} data
@:*/
@:export function treelist@(genTable.FunctionCode)(query) {
    @:return request({
    @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/treelist',
    @:method: 'get',
    @:params: query,
    @:})
@:}
}

@if(replaceDto.ShowBtnAdd)
{
@:/**
 @:* 新增@(genTable.FunctionName)
 @:* @@param data
 @:*/
@:export function add@(genTable.FunctionCode)(data) {
  @:return request({
    @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/add',
    @:method: 'post',
    @:data: data,
  @:})
@:}
}

@if(replaceDto.ShowBtnEdit)
{
@:/**
 @:* 修改@(genTable.FunctionName)
 @:* @@param data
 @:*/
@:export function modify@(genTable.FunctionCode)(data) {
  @:return request({
    @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/modify',
    @:method: 'post',
    @:data: data,
  @:})
@:}
}

@if(genTableOptions.IsHasEnableStateField && genTableOptions.IsEnableStateChange)
{
@:export function change@(genTable.FunctionCode)State(data) {
    @:return request({
        @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/changeState',
        @:method: 'post',
        @:data: data,
    @:})
@:}
}


/**
 * 获取@(genTable.FunctionName)详情
 * @@param {Id}
 */
export function get@(genTable.FunctionCode)Detail(id) {
  return request({
    url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/detail/' + id,
    method: 'get'
  })
}

@if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
{
@:/**
 @:* 删除@(genTable.FunctionName)
 @:* @@param {主键} pid
 @:*/
@:export function del@(genTable.FunctionCode)(data) {
  @:return request({
    @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/delete',
    @:method: 'post',
    @:data:data
  @:})
@:}
}

@if(replaceDto.ShowBtnExport)
{
@:// 导出@(genTable.FunctionName)列表
@:export async function export@(genTable.FunctionCode)List(query) {
  @:await downFile('@(genTable.ModuleCode)/@(bizNameFirstLower)/exportList', { ...query })
@:}
}
@if(showCustomInput)
{
@:export function changeSort(data) {
  @:return request({
    @:url: '@(genTable.ModuleCode)/@(bizNameFirstLower)/ChangeSort',
    @:method: 'get',
    @:params: data
  @:})
@:}
}